package com.dayu.sale.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.sale.domain.DySaleParts;
import com.dayu.sale.service.IDySalePartsService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 版本3 --- 出售配件Controller
 *
 * @author HK
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/sale/parts")
public class DySalePartsController extends BaseController
{
    @Autowired
    private IDySalePartsService dySalePartsService;

    /**
     * 查询版本3 --- 出售配件列表
     */
    @PreAuthorize("@ss.hasPermi('sale:parts:list')")
    @GetMapping("/list")
    public TableDataInfo list(DySaleParts dySaleParts)
    {
        startPage();
        List<DySaleParts> list = dySalePartsService.selectDySalePartsList(dySaleParts);
        return getDataTable(list);
    }

    /**
     * 导出版本3 --- 出售配件列表
     */
    @PreAuthorize("@ss.hasPermi('sale:parts:export')")
    @Log(title = "版本3 --- 出售配件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DySaleParts dySaleParts)
    {
        List<DySaleParts> list = dySalePartsService.selectDySalePartsList(dySaleParts);
        ExcelUtil<DySaleParts> util = new ExcelUtil<DySaleParts>(DySaleParts.class);
        return util.exportExcel(list, "parts");
    }

    /**
     * 获取版本3 --- 出售配件详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:parts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dySalePartsService.selectDySalePartsById(id));
    }

    /**
     * 新增版本3 --- 出售配件
     */
    @PreAuthorize("@ss.hasPermi('sale:parts:add')")
    @Log(title = "版本3 --- 出售配件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DySaleParts dySaleParts)
    {
        return toAjax(dySalePartsService.insertDySaleParts(dySaleParts));
    }

    /**
     * 修改版本3 --- 出售配件
     */
    @PreAuthorize("@ss.hasPermi('sale:parts:edit')")
    @Log(title = "版本3 --- 出售配件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DySaleParts dySaleParts)
    {
        return toAjax(dySalePartsService.updateDySaleParts(dySaleParts));
    }
}
